//
//  KoiToolbarView.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 01.04.25.
//

import SwiftUI

struct KoiToolbarView<MenuView: View>: View {
    
    @Binding var title: String
    
    @ViewBuilder let menuView: () -> MenuView
    
    var backClick: (() -> Void)? = nil
    
    init(title: Binding<String>, menuView: @escaping () -> MenuView = {EmptyView()}, backClick: ( () -> Void)? = nil) {
        _title = title
        self.menuView = menuView
        self.backClick = backClick
    }
    
    var body: some View {
        ZStack {
            HStack {
                KoiBackButton(onBackClick: backClick)
                Spacer()
            }
            HStack {
                Spacer()
                Text(title)
                    .font(.system(size: 16))
                    .bold()
                    .foregroundColor(Color.koiColorTitle)
                Spacer()
            }
            HStack {
                Spacer()
                menuView().padding(.trailing, 14)
            }
        }.padding(EdgeInsets(top: 11, leading: 0, bottom: 11, trailing: 0))
    }
}

@available(iOS 18.0, *)
#Preview {
    @Previewable @State var title = "标题"
    KoiToolbarView(title: $title, menuView: {Text("测试")})
}
